package robocup.component.speechacts.coachlanguage;

import java.util.LinkedList;

public class Region {

  private TypeConstants.REGIONTYPE regionType = TypeConstants.REGIONTYPE.INIT;

  private String                   regionName = "";

  private CPoint                   point      = null;

  private CPoint                   recPoint1  = null;

  private CPoint                   recPoint2  = null;

  private CPoint                   triPoint1  = null;

  private CPoint                   triPoint2  = null;

  private CPoint                   triPoint3  = null;

  private CPoint                   quadPoint1 = null;

  private CPoint                   quadPoint2 = null;

  private CPoint                   quadPoint3 = null;

  private CPoint                   quadPoint4 = null;

  private CPoint                   arcPoint   = null;

  private double                   arcReal1   = 0;

  private double                   arcReal2   = 0;

  private double                   arcReal3   = 0;

  private double                   arcReal4   = 0;

  private LinkedList<Region>       regionList = new LinkedList<Region>();

  public void addRegion(final Region region) {

    this.regionList.add(region);
    this.regionType = TypeConstants.REGIONTYPE.REG;

  }

  public String getRegionName() {

    return this.regionName;
  }

  public void setRegionName(final String regionName) {

    this.regionName = regionName;
    this.regionType = TypeConstants.REGIONTYPE.NAME;
  }

  public TypeConstants.REGIONTYPE getRegionType() {

    return this.regionType;
  }

  public void setRegionType(final TypeConstants.REGIONTYPE regionType) {

    this.regionType = regionType;
  }

  public void setNull() {

    this.regionType = TypeConstants.REGIONTYPE.NULL;
  }

  public CPoint getPoint() {

    return this.point;
  }

  public void setPoint(final CPoint point) {

    this.point = point;
    this.regionType = TypeConstants.REGIONTYPE.POINT;
  }

  public CPoint getArcPoint() {

    return this.arcPoint;
  }

  public void setArcPoint(final CPoint arcPoint) {

    this.arcPoint = arcPoint;
    this.regionType = TypeConstants.REGIONTYPE.ARC;
  }

  public double getArcReal1() {

    return this.arcReal1;
  }

  public void setArcReal1(final double arcReal1) {

    this.arcReal1 = arcReal1;
    this.regionType = TypeConstants.REGIONTYPE.ARC;
  }

  public double getArcReal2() {

    return this.arcReal2;
  }

  public void setArcReal2(final double arcReal2) {

    this.arcReal2 = arcReal2;
    this.regionType = TypeConstants.REGIONTYPE.ARC;
  }

  public double getArcReal3() {

    return this.arcReal3;
  }

  public void setArcReal3(final double arcReal3) {

    this.arcReal3 = arcReal3;
    this.regionType = TypeConstants.REGIONTYPE.ARC;
  }

  public double getArcReal4() {

    return this.arcReal4;
  }

  public void setArcReal4(final double arcReal4) {

    this.arcReal4 = arcReal4;
    this.regionType = TypeConstants.REGIONTYPE.ARC;
  }

  public CPoint getRecPoint1() {

    return this.recPoint1;
  }

  public void setRecPoint1(final CPoint recPoint1) {

    this.recPoint1 = recPoint1;
    this.regionType = TypeConstants.REGIONTYPE.REC;
  }

  public CPoint getRecPoint2() {

    return this.recPoint2;
  }

  public void setRecPoint2(final CPoint recPoint2) {

    this.recPoint2 = recPoint2;
    this.regionType = TypeConstants.REGIONTYPE.REC;
  }

  public CPoint getTriPoint1() {

    return this.triPoint1;
  }

  public void setTriPoint1(final CPoint triPoint1) {

    this.triPoint1 = triPoint1;
    this.regionType = TypeConstants.REGIONTYPE.TRI;
  }

  public CPoint getTriPoint2() {

    return this.triPoint2;
  }

  public void setTriPoint2(final CPoint triPoint2) {

    this.triPoint2 = triPoint2;
    this.regionType = TypeConstants.REGIONTYPE.TRI;
  }

  public CPoint getTriPoint3() {

    return this.triPoint3;
  }

  public void setTriPoint3(final CPoint triPoint3) {

    this.triPoint3 = triPoint3;
    this.regionType = TypeConstants.REGIONTYPE.TRI;
  }

  public LinkedList<Region> getRegionList() {

    return this.regionList;
  }

  public void setRegionList(final LinkedList<Region> regionList) {

    this.regionList = regionList;
    this.regionType = TypeConstants.REGIONTYPE.REG;
  }

  public CPoint getQuadPoint1() {

    return this.quadPoint1;
  }

  public void setQuadPoint1(final CPoint quadPoint1) {

    this.quadPoint1 = quadPoint1;
    this.regionType = TypeConstants.REGIONTYPE.QUAD;
  }

  public CPoint getQuadPoint2() {

    return this.quadPoint2;
  }

  public void setQuadPoint2(final CPoint quadPoint2) {

    this.quadPoint2 = quadPoint2;
    this.regionType = TypeConstants.REGIONTYPE.QUAD;
  }

  public CPoint getQuadPoint3() {

    return this.quadPoint3;
  }

  public void setQuadPoint3(final CPoint quadPoint3) {

    this.quadPoint3 = quadPoint3;
    this.regionType = TypeConstants.REGIONTYPE.QUAD;
  }

  public CPoint getQuadPoint4() {

    return this.quadPoint4;
  }

  public void setQuadPoint4(final CPoint quadPoint4) {

    this.quadPoint4 = quadPoint4;
    this.regionType = TypeConstants.REGIONTYPE.QUAD;
  }

  @Override
  public String toString() {

    final StringBuffer buf = new StringBuffer();

    switch (this.regionType) {

      case INIT:
        buf.append("(empty region)");
        break;

      case NAME:
        buf.append(this.regionName);
        break;

      case NULL:
        buf.append("(null)");
        break;

      case ARC:
        buf.append("(arc " + this.arcPoint.toString());
        buf.append(" " + this.arcReal1);
        buf.append(" " + this.arcReal2);
        buf.append(" " + this.arcReal3);
        buf.append(" " + this.arcReal4 + ")");
        break;

      case REG:
        buf.append("(reg");

        for (final Region reg : this.regionList) {
          buf.append(" " + reg.toString());
        }

        buf.append(")");
        break;

      case REC:
        buf.append("(rec");
        buf.append(" " + this.recPoint1.toString());
        buf.append(" " + this.recPoint2.toString() + ")");
        break;

      case TRI:
        buf.append("(tri");
        buf.append(" " + this.triPoint1.toString());
        buf.append(" " + this.triPoint2.toString());
        buf.append(" " + this.triPoint3.toString() + ")");
        break;

      case QUAD:
        buf.append("(quad");
        buf.append(" " + this.quadPoint1.toString());
        buf.append(" " + this.quadPoint2.toString());
        buf.append(" " + this.quadPoint3.toString());
        buf.append(" " + this.quadPoint4.toString() + ")");
        break;

      case POINT:
        buf.append(this.point.toString());
        break;
    }

    return buf.toString();

  }

}
